<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/6
  Time: 16:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<html>
  <head>
    <base href="${pageContext.request.contextPath}/">
    <title>水果查询</title>
    <style>
      table tr:nth-child(odd){
        background: darkgray;
      }
    </style>
    <script src="jq/jquery.js"></script>
  </head>
  <body>
  <div align="center">
    <form action="">
      <table border="1px" id="table">
        <tr align="center">
          <th>类别</th>
          <th>品种</th>
          <th>产地</th>
          <th>总重量（公斤）</th>
          <th>单价（元/公斤）</th>
          <th>操作</th>
        </tr>
        <c:forEach items="${sessionScope.list}" var="fruit" >
          <tr>
            <td>${fruit.type}</td>
            <td>${fruit.breed}</td>
            <td>${fruit.area}</td>
            <td>${fruit.weight}</td>
            <td>${fruit.price}</td>
            <td><a href="DetailsServlet?id=${fruit.fruitId}">详情</a>&nbsp;<a href="javascript:void(0)" onclick="remove('${fruit.fruitId}')">删除</a></td>
          </tr>
        </c:forEach>
      </table>
    </form>
  </div>
  <script>
    function remove(id) {
      if(confirm("确定要删除吗？")) {
        $.getJSON(
                "DeleteServlet",
                {id: id},
                function (data) {
                  if (data) {
                    alert("删除成功！");
                    location.href="ListServlet"
                  } else {
                    alert("删除失败！")
                  }
                }
        )
      }
    }
  </script>
  </body>
</html>
